<?php
class QArchiveLog
{	
	public function __construct($p_strCountry)
	{
		$this->_country	= $p_strCountry;
		$this->_table	= strtolower($p_strCountry).'_archive_logs';
	}
	
	public function get_all()
	{
		$strQuery	= '
		    SELECT "' .$this->_country . '_archives" as iname , "" as createdate, "" as admin_username' . 
			' Union All '.
			' SELECT al.iname, al.createdate as createdate, a.admin_username
			FROM '.$this->_table.' al
				INNER JOIN admins a ON al.admin_id=a.admin_id
			ORDER BY createdate DESC
			';
		$db 	= Zend_Registry::get('db');
		$resultValue =  $db->fetchAll($strQuery);
		$db->closeConnection();
		return $resultValue;
	}
	
	public function get_by_id($p_strName)
	{
		$strQuery	= '
			SELECT *
			FROM '.$this->_table.' 
			WHERE LOWER(iname)="'.strtolower(trim($p_strName)).'"
			';
		$db 		= Zend_Registry::get('db');
		$arrResult  = $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	public function total()
	{
		$strQuery	= '
			SELECT COUNT(iname) AS total
			FROM '.$this->_table.'
			';
		$db 		= Zend_Registry::get('db');
		$arrResult 	= $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]['total']) ? $arrResult[0]['total'] : 0;
	}
	
	public function delete($p_strName)
	{
		$p_strName	= strtolower(trim($p_strName));
		$strQuery	= '
			DROP TABLE '.$p_strName.';
			DELETE FROM '.$this->_table.' WHERE LOWER(iname)="'.strtolower(trim($p_strName)).'";
		';
		$db 	= Zend_Registry::get('db');
		$resultValue = $db->execute($strQuery);
		$db->closeConnection();
		return $resultValue;
	}
}
?>